
import ResManager from "../manager/ResManager";
import Unit from "./Unit";
const animDirection = {
    '01': '1',
    '11': '2',
    '10': '3',
    '1-1': '4',
    '0-1': '5',
    '-1-1': '6',
    '-10': '7',
    '-11': '8',
}
export default class AnimationComponent {
    unit: Unit = null;
    direction: cc.Vec2 = new cc.Vec2();
    animation: cc.Animation = null;
    currentState: string = null;
    constructor(unit: Unit) {
        this.unit = unit;
        unit.anim = this;
        this.animation = unit.node.children[0].getComponent(cc.Animation);
        ResManager.instance.createAnimas(this.unit.unitId,this.animation);
    }
    switchDirection(dir: cc.Vec2) {
        this.direction = dir;
        
        this.animation.play(this.currentState + animDirection['' + this.direction.x + this.direction.y]);
    }
    clear() {
        this.animation.stop();
    }
    play(animName: string) {
        this.currentState = animName;
        this.animation.play(this.currentState + animDirection['' + this.direction.x + this.direction.y]);
    }
}
